package gui;


import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;

public class AddColumnGridLayout {
  public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    final GridLayout grid = new GridLayout(1, false);
    shell.setLayout(grid);
    
    Button b = new Button(shell, SWT.NONE);
    b.setText("add Colum");
    
    
    Listener l = new Listener()
	{
		@Override
		public void handleEvent(Event arg0)
		{
			GridLayout p = (GridLayout) shell.getLayout();
			int gridCols= p.numColumns+1;
			GridLayout gridN =  new GridLayout(gridCols, false);
			shell.setLayout(gridN);
			System.out.println(gridCols);
			
		    	Label l = new Label(shell, SWT.NONE);
		    	l.setText(gridCols+"");
		    	l.setSize(50, 20);
		    	l.setBackground(new Color(Display.getCurrent (), 255,0,255));
		    
			
			shell.layout();
		
		}
	}; 
	
	b.addListener(SWT.Selection, l);


   // Table table = new Table(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);

    shell.open();

    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }
    display.dispose();
  }
}
